package com.feng.utils
{
	import com.feng.FengData;
	import com.feng.data.UpgradeType;
	import com.feng.debug.logger;

	public class PlayerUtils
	{
		public static function copy(player:Object):Object
		{
			var newPlayer:Object = {};

			for (var key:String in player)
			{
				newPlayer[key] = player[key];
			}
			return newPlayer;
		}

		public static function attackDamage(attacker:Object, target:Object):int
		{
			//5、伤害计算公式是“攻击减防御”，但最小伤害不低于5点。
			var damage:int = attacker.atk - target.def;
			if (damage < FengData.MIN_DAMAGE)
			{
				damage = FengData.MIN_DAMAGE;
			}
			return damage;
		}

		public static function upgrade(player:Object, upgradeType:int):Object
		{
			var newPlayer:Object = copy(player);
			switch (upgradeType)
			{
				case UpgradeType.ADD_ATTACK:
					newPlayer.atk += 4;
					break;
				case UpgradeType.ADD_DEFENSE:
					newPlayer.def += 3;
					break;
				case UpgradeType.ADD_SPEED:
					newPlayer.spd += 2;
					break;
				case UpgradeType.ADD_ALL:
					newPlayer.atk++;
					newPlayer.def++;
					newPlayer.spd++;
					break;
				default:
					logger("脑子进水了，居然想提升没有的属性！");
					break;
			}
			return newPlayer;
		}
	}
}
